﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DTTB.MV2.QUANLYNHANSUTIENLUONG.BussinessDelegate.DanhMucDelegate;
using DTTB.MV2.QUANLYNHANSUTIENLUONG.Models.FormBean.DanhMuc;
using DTTB.MV2.QUANLYNHANSUTIENLUONG.Models.LinQ.DanhMuc;

namespace DTTB.MV2.QUANLYNHANSUTIENLUONG.Controllers
{
    public class DanhMucController : Controller
    {

        #region phần xử lý cho DANH MỤC dân tộc


        DanTocDelegate DanTocDelegate = new DanTocDelegate();

        //....phần xử lý cho DANH MỤC dân tộc .............................................
        public ActionResult DanToc(int? PageNumber, string status)// id : page number
        {
            DanTocForm DanTocForm = new DanTocForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                DanTocForm.MessageCreateDanToc = "Tạo mới thành công !";
            }
            DanTocForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            DanTocForm.DanTocPagedList = DanTocDelegate.GetDanTocPagedList(PageNumber);
            DanTocForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/DanToc.aspx", DanTocForm);
        }
        public ActionResult RecycleBinDanToc(int? PageNumber)// id : page number
        {
            DanTocForm DanTocForm = new DanTocForm();
            DanTocForm.RecycleDanTocPagedList = DanTocDelegate.RecycleGetDanTocPagedList(PageNumber);
            DanTocForm.count = DanTocForm.RecycleDanTocPagedList.Count;
            DanTocForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinDanToc.aspx", DanTocForm);
        }
        //Create dân tộc
        public ActionResult TaoDanToc(DanTocForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_DanToc newDanToc = this.DanTocDelegate.BuildNewDanToc(form);
            if (form.id == -1)
            {
                try
                {
                    newDanToc = this.DanTocDelegate.AddNewDanToc(newDanToc);
                    form.MessageCreateDanToc = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateDanToc = "0";
                }
            }

            //Refesh form
            form.id = newDanToc.Id;
            form.DanTocPagedList = DanTocDelegate.GetDanTocPagedList(form.Pagenumber);
            form.RecycleDanTocPagedList = DanTocDelegate.RecycleGetDanTocPagedList(form.Pagenumber);
            return RedirectToAction("DanToc", new { status = form.MessageCreateDanToc });
            //return View("~/Views/QuanLyDanhMuc/DanToc.aspx", form);
        }

        //Edit DanToc
        public ActionResult ChinhSuaDanToc(DanTocForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_DanToc editCap = this.DanTocDelegate.BuildEditDanToc(form);
            if (!string.IsNullOrEmpty(form.TenDanToc))
            {

                try
                {
                    this.DanTocDelegate.UpdateDanToc(editCap);
                    form.MessageEditDanToc = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditDanToc = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.DanTocPagedList = DanTocDelegate.GetDanTocPagedList(form.Pagenumber);
            form.RecycleDanTocPagedList = DanTocDelegate.RecycleGetDanTocPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/DanToc.aspx", form);
        }
        public JsonResult DeleteDanToc(string DanTocId)// id la IdDanToc
        {
            dm_DanToc DeleteCap = this.DanTocDelegate.GetDanTocById(DanTocId.ToString());
            DeleteCap.IsDelete = true;
            if (this.DanTocDelegate.DeleteDanToc(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục dân tộc
        public ActionResult TimKiemDanToc(string DanToc, int? PageNumber)// id : page number
        {
            DanTocForm form = new DanTocForm();
            if (DanToc == null)
            {
                DanToc = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới
            form.valuesearch = Convert.ToString(DanToc);
            form.DanTocPagedList = DanTocDelegate.SearchDanTocPagedList(PageNumber, DanToc);// id : page number
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/DanToc.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTenDanTocExistAjax(string TenDanToc, int id)
        {
            dm_DanToc item = this.DanTocDelegate.GetDanTocByTenCheck(TenDanToc);

            //bool result = item != null ? true : false;
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult DanTocEditAjax(string id)
        {
            dm_DanToc item = this.DanTocDelegate.GetDanTocById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TenDanToc };
            return Json(kq, JsonRequestBehavior.AllowGet);
            //return Json(item, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiDanToc(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.DanTocDelegate.PhucHoiDanToc(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.DanTocDelegate.DeleteDanToc(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanDanToc(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.DanTocDelegate.DeleteDanToc(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC phụ cấp điện thoại


        PCDienThoaiDelegate PCDienThoaiDelegate = new PCDienThoaiDelegate();

        //....phần xử lý cho DANH MỤC phụ cấp điện thoại .............................................
        public ActionResult PCDienThoai(int? PageNumber, string status)// id : page number
        {
            PCDienThoaiForm PCDienThoaiForm = new PCDienThoaiForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                PCDienThoaiForm.MessageCreatePCDienThoai = "Tạo mới thành công !";
            }
            PCDienThoaiForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            PCDienThoaiForm.PCDienThoaiPagedList = PCDienThoaiDelegate.GetPCDienThoaiPagedList(PageNumber);
            PCDienThoaiForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/PCDienThoai.aspx", PCDienThoaiForm);
        }
        public ActionResult RecycleBinPCDienThoai(int? PageNumber)// id : page number
        {
            PCDienThoaiForm PCDienThoaiForm = new PCDienThoaiForm();
            PCDienThoaiForm.RecyclePCDienThoaiPagedList = PCDienThoaiDelegate.RecycleGetPCDienThoaiPagedList(PageNumber);
            PCDienThoaiForm.count = PCDienThoaiForm.RecyclePCDienThoaiPagedList.Count;
            PCDienThoaiForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinPCDienThoai.aspx", PCDienThoaiForm);
        }
        //Create phụ cấp điện thoại
        public ActionResult TaoPCDienThoai(PCDienThoaiForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_PCDienThoai newPCDienThoai = this.PCDienThoaiDelegate.BuildNewPCDienThoai(form);
            if (form.id == -1)
            {
                try
                {
                    newPCDienThoai = this.PCDienThoaiDelegate.AddNewPCDienThoai(newPCDienThoai);
                    form.MessageCreatePCDienThoai = "1";
                }
                catch (Exception)
                {
                    form.MessageCreatePCDienThoai = "0";
                }
            }

            //Refesh form
            form.id = newPCDienThoai.Id;
            form.PCDienThoaiPagedList = PCDienThoaiDelegate.GetPCDienThoaiPagedList(form.Pagenumber);
            form.RecyclePCDienThoaiPagedList = PCDienThoaiDelegate.RecycleGetPCDienThoaiPagedList(form.Pagenumber);
            return RedirectToAction("PCDienThoai", new { status = form.MessageCreatePCDienThoai });
        }

        //Edit PCDienThoai
        public ActionResult ChinhSuaPCDienThoai(PCDienThoaiForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_PCDienThoai editCap = this.PCDienThoaiDelegate.BuildEditPCDienThoai(form);
            if (!string.IsNullOrEmpty(form.TienPCDienThoai))
            {

                try
                {
                    this.PCDienThoaiDelegate.UpdatePCDienThoai(editCap);
                    form.MessageEditPCDienThoai = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditPCDienThoai = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.PCDienThoaiPagedList = PCDienThoaiDelegate.GetPCDienThoaiPagedList(form.Pagenumber);
            form.RecyclePCDienThoaiPagedList = PCDienThoaiDelegate.RecycleGetPCDienThoaiPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/PCDienThoai.aspx", form);
        }
        public JsonResult DeletePCDienThoai(string PCDienThoaiId)// id la IdPCDienThoai
        {
            dm_PCDienThoai DeleteCap = this.PCDienThoaiDelegate.GetPCDienThoaiById(PCDienThoaiId.ToString());
            DeleteCap.IsDelete = true;
            if (this.PCDienThoaiDelegate.DeletePCDienThoai(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục phụ cấp điện thoại
        public ActionResult TimKiemPCDienThoai(string PCDienThoai, int? PageNumber)// id : page number
        {
            PCDienThoaiForm form = new PCDienThoaiForm();
            if (PCDienThoai == null)
            {
                PCDienThoai = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới
            form.valuesearch = Convert.ToString(PCDienThoai);
            if (!string.IsNullOrEmpty(PCDienThoai))
            {
                PCDienThoai = PCDienThoai.Replace(".", "");
                form.PCDienThoaiPagedList = PCDienThoaiDelegate.SearchPCDienThoaiPagedList(PageNumber, PCDienThoai);// id : page number
            }
            else
            {
                form.PCDienThoaiPagedList = PCDienThoaiDelegate.GetPCDienThoaiPagedList(PageNumber);
            }
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/PCDienThoai.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTienPCDienThoaiExistAjax(string TienPCDienThoai, int id)
        {
            decimal TienPC;
            if (!string.IsNullOrEmpty(TienPCDienThoai))
                TienPC =decimal.Parse(TienPCDienThoai.Replace(".", ""));
            else return Json(false, JsonRequestBehavior.AllowGet);
            dm_PCDienThoai item = this.PCDienThoaiDelegate.GetPCDienThoaiByTenCheck(TienPC);

            //bool result = item != null ? true : false;
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PCDienThoaiEditAjax(string id)
        {
            dm_PCDienThoai item = this.PCDienThoaiDelegate.GetPCDienThoaiById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TienPCDienThoai!=null?item.TienPCDienThoai.Value.ToString("#,#").Replace(",","."):"" };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiPCDienThoai(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.PCDienThoaiDelegate.PhucHoiPCDienThoai(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.PCDienThoaiDelegate.DeletePCDienThoai(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanPCDienThoai(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.PCDienThoaiDelegate.DeletePCDienThoai(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC phụ cấp đi lại


        PhuCapDiLaiDelegate PhuCapDiLaiDelegate = new PhuCapDiLaiDelegate();

        //....phần xử lý cho DANH MỤC phụ cấp đi lại .............................................
        public ActionResult PhuCapDiLai(int? PageNumber, string status)// id : page number
        {
            PhuCapDiLaiForm PhuCapDiLaiForm = new PhuCapDiLaiForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                PhuCapDiLaiForm.MessageCreatePhuCapDiLai = "Tạo mới thành công !";
            }
            PhuCapDiLaiForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            PhuCapDiLaiForm.PhuCapDiLaiPagedList = PhuCapDiLaiDelegate.GetPhuCapDiLaiPagedList(PageNumber);
            PhuCapDiLaiForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/PhuCapDiLai.aspx", PhuCapDiLaiForm);
        }
        public ActionResult RecycleBinPhuCapDiLai(int? PageNumber)// id : page number
        {
            PhuCapDiLaiForm PhuCapDiLaiForm = new PhuCapDiLaiForm();
            PhuCapDiLaiForm.RecyclePhuCapDiLaiPagedList = PhuCapDiLaiDelegate.RecycleGetPhuCapDiLaiPagedList(PageNumber);
            PhuCapDiLaiForm.count = PhuCapDiLaiForm.RecyclePhuCapDiLaiPagedList.Count;
            PhuCapDiLaiForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinPhuCapDiLai.aspx", PhuCapDiLaiForm);
        }
        //Create phụ cấp đi lại
        public ActionResult TaoPhuCapDiLai(PhuCapDiLaiForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_PhuCapDiLai newPhuCapDiLai = this.PhuCapDiLaiDelegate.BuildNewPhuCapDiLai(form);
            if (form.id == -1)
            {
                try
                {
                    newPhuCapDiLai = this.PhuCapDiLaiDelegate.AddNewPhuCapDiLai(newPhuCapDiLai);
                    form.MessageCreatePhuCapDiLai = "1";
                }
                catch (Exception)
                {
                    form.MessageCreatePhuCapDiLai = "0";
                }
            }

            //Refesh form
            form.id = newPhuCapDiLai.Id;
            form.PhuCapDiLaiPagedList = PhuCapDiLaiDelegate.GetPhuCapDiLaiPagedList(form.Pagenumber);
            form.RecyclePhuCapDiLaiPagedList = PhuCapDiLaiDelegate.RecycleGetPhuCapDiLaiPagedList(form.Pagenumber);
            return RedirectToAction("PhuCapDiLai", new { status = form.MessageCreatePhuCapDiLai });
        }

        //Edit PhuCapDiLai
        public ActionResult ChinhSuaPhuCapDiLai(PhuCapDiLaiForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_PhuCapDiLai editCap = this.PhuCapDiLaiDelegate.BuildEditPhuCapDiLai(form);
            if (!string.IsNullOrEmpty(form.TienPhuCapDiLai))
            {

                try
                {
                    this.PhuCapDiLaiDelegate.UpdatePhuCapDiLai(editCap);
                    form.MessageEditPhuCapDiLai = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditPhuCapDiLai = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.PhuCapDiLaiPagedList = PhuCapDiLaiDelegate.GetPhuCapDiLaiPagedList(form.Pagenumber);
            form.RecyclePhuCapDiLaiPagedList = PhuCapDiLaiDelegate.RecycleGetPhuCapDiLaiPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/PhuCapDiLai.aspx", form);
        }
        public JsonResult DeletePhuCapDiLai(string PhuCapDiLaiId)// id la IdPhuCapDiLai
        {
            dm_PhuCapDiLai DeleteCap = this.PhuCapDiLaiDelegate.GetPhuCapDiLaiById(PhuCapDiLaiId.ToString());
            DeleteCap.IsDelete = true;
            if (this.PhuCapDiLaiDelegate.DeletePhuCapDiLai(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục phụ cấp đi lại
        public ActionResult TimKiemPhuCapDiLai(string PhuCapDiLai, int? PageNumber)// id : page number
        {
            PhuCapDiLaiForm form = new PhuCapDiLaiForm();
            if (PhuCapDiLai == null)
            {
                PhuCapDiLai = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(PhuCapDiLai);
            if (!string.IsNullOrEmpty(PhuCapDiLai))
            {
                PhuCapDiLai = PhuCapDiLai.Replace(".", "");
                form.PhuCapDiLaiPagedList = PhuCapDiLaiDelegate.SearchPhuCapDiLaiPagedList(PageNumber, PhuCapDiLai);// id : page number
            }
            else
            {
                form.PhuCapDiLaiPagedList = PhuCapDiLaiDelegate.GetPhuCapDiLaiPagedList(PageNumber);
            }
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/PhuCapDiLai.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTienPhuCapDiLaiExistAjax(string TienPhuCapDiLai, int id)
        {
            decimal TienPC;
            if (!string.IsNullOrEmpty(TienPhuCapDiLai))
                TienPC = decimal.Parse(TienPhuCapDiLai.Replace(".", ""));
            else return Json(false, JsonRequestBehavior.AllowGet);
            dm_PhuCapDiLai item = this.PhuCapDiLaiDelegate.GetPhuCapDiLaiByTenCheck(TienPC);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhuCapDiLaiEditAjax(string id)
        {
            dm_PhuCapDiLai item = this.PhuCapDiLaiDelegate.GetPhuCapDiLaiById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TienPhuCapDiLai != null ? item.TienPhuCapDiLai.Value.ToString("#,#").Replace(",", ".") : "" };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiPhuCapDiLai(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.PhuCapDiLaiDelegate.PhucHoiPhuCapDiLai(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.PhuCapDiLaiDelegate.DeletePhuCapDiLai(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanPhuCapDiLai(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.PhuCapDiLaiDelegate.DeletePhuCapDiLai(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC phụ cấp Tiền cơm


        TienComDelegate TienComDelegate = new TienComDelegate();

        //....phần xử lý cho DANH MỤC phụ cấp tiền cơm .............................................
        public ActionResult TienCom(int? PageNumber, string status)// id : page number
        {
            TienComForm TienComForm = new TienComForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                TienComForm.MessageCreateTienCom = "Tạo mới thành công !";
            }
            TienComForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            TienComForm.TienComPagedList = TienComDelegate.GetTienComPagedList(PageNumber);
            TienComForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TienCom.aspx", TienComForm);
        }
        public ActionResult RecycleBinTienCom(int? PageNumber)// id : page number
        {
            TienComForm TienComForm = new TienComForm();
            TienComForm.RecycleTienComPagedList = TienComDelegate.RecycleGetTienComPagedList(PageNumber);
            TienComForm.count = TienComForm.RecycleTienComPagedList.Count;
            TienComForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinTienCom.aspx", TienComForm);
        }
        //Create phụ cấp tiền cơm
        public ActionResult TaoTienCom(TienComForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TienCom newTienCom = this.TienComDelegate.BuildNewTienCom(form);
            if (form.id == -1)
            {
                try
                {
                    newTienCom = this.TienComDelegate.AddNewTienCom(newTienCom);
                    form.MessageCreateTienCom = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateTienCom = "0";
                }
            }

            //Refesh form
            form.id = newTienCom.Id;
            form.TienComPagedList = TienComDelegate.GetTienComPagedList(form.Pagenumber);
            form.RecycleTienComPagedList = TienComDelegate.RecycleGetTienComPagedList(form.Pagenumber);
            return RedirectToAction("TienCom", new { status = form.MessageCreateTienCom });
        }

        //Edit TienCom
        public ActionResult ChinhSuaTienCom(TienComForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TienCom editCap = this.TienComDelegate.BuildEditTienCom(form);
            if (!string.IsNullOrEmpty(form.TienC))
            {

                try
                {
                    this.TienComDelegate.UpdateTienCom(editCap);
                    form.MessageEditTienCom = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditTienCom = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.TienComPagedList = TienComDelegate.GetTienComPagedList(form.Pagenumber);
            form.RecycleTienComPagedList = TienComDelegate.RecycleGetTienComPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/TienCom.aspx", form);
        }
        public JsonResult DeleteTienCom(string TienComId)// id la IdTienCom
        {
            dm_TienCom DeleteCap = this.TienComDelegate.GetTienComById(TienComId);
            DeleteCap.IsDelete = true;
            if (this.TienComDelegate.DeleteTienCom(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục phụ cấp tiền cơm
        public ActionResult TimKiemTienCom(string TienCom, int? PageNumber)// id : page number
        {
            TienComForm form = new TienComForm();
            if (TienCom == null)
            {
                TienCom = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(TienCom);
            if (!string.IsNullOrEmpty(TienCom))
            {
                TienCom = TienCom.Replace(".", "");
                form.TienComPagedList = TienComDelegate.SearchTienComPagedList(PageNumber, TienCom);// id : page number
            }
            else
            {
                form.TienComPagedList = TienComDelegate.GetTienComPagedList(PageNumber);
            }
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TienCom.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTienComExistAjax(string TienCom, int id)
        {
            decimal TienPC;
            if (!string.IsNullOrEmpty(TienCom))
                TienPC = decimal.Parse(TienCom.Replace(".", ""));
            else return Json(false, JsonRequestBehavior.AllowGet);
            dm_TienCom item = this.TienComDelegate.GetTienComByTenCheck(TienPC);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult TienComEditAjax(string id)
        {
            dm_TienCom item = this.TienComDelegate.GetTienComById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TienCom != null ? item.TienCom.Value.ToString("#,#").Replace(",", ".") : "" };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiTienCom(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.TienComDelegate.PhucHoiTienCom(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.TienComDelegate.DeleteTienCom(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanTienCom(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.TienComDelegate.DeleteTienCom(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC phụ cấp tiền lương cơ bản


        TienLuongCoBanDelegate TienLuongCoBanDelegate = new TienLuongCoBanDelegate();

        //....phần xử lý cho DANH MỤC phụ cấp tiền lương cơ bản .............................................
        public ActionResult TienLuongCoBan(int? PageNumber, string status)// id : page number
        {
            TienLuongCoBanForm TienLuongCoBanForm = new TienLuongCoBanForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                TienLuongCoBanForm.MessageCreateTienLuongCoBan = "Tạo mới thành công !";
            }
            TienLuongCoBanForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            TienLuongCoBanForm.TienLuongCoBanPagedList = TienLuongCoBanDelegate.GetTienLuongCoBanPagedList(PageNumber);
            TienLuongCoBanForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TienLuongCoBan.aspx", TienLuongCoBanForm);
        }
        public ActionResult RecycleBinTienLuongCoBan(int? PageNumber)// id : page number
        {
            TienLuongCoBanForm TienLuongCoBanForm = new TienLuongCoBanForm();
            TienLuongCoBanForm.RecycleTienLuongCoBanPagedList = TienLuongCoBanDelegate.RecycleGetTienLuongCoBanPagedList(PageNumber);
            TienLuongCoBanForm.count = TienLuongCoBanForm.RecycleTienLuongCoBanPagedList.Count;
            TienLuongCoBanForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinTienLuongCoBan.aspx", TienLuongCoBanForm);
        }
        //Create phụ cấp tiền lương cơ bản
        public ActionResult TaoTienLuongCoBan(TienLuongCoBanForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TienLuongCoBan newTienLuongCoBan = this.TienLuongCoBanDelegate.BuildNewTienLuongCoBan(form);
            if (form.id == -1)
            {
                try
                {
                    newTienLuongCoBan = this.TienLuongCoBanDelegate.AddNewTienLuongCoBan(newTienLuongCoBan);
                    form.MessageCreateTienLuongCoBan = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateTienLuongCoBan = "0";
                }
            }

            //Refesh form
            form.id = newTienLuongCoBan.Id;
            form.TienLuongCoBanPagedList = TienLuongCoBanDelegate.GetTienLuongCoBanPagedList(form.Pagenumber);
            form.RecycleTienLuongCoBanPagedList = TienLuongCoBanDelegate.RecycleGetTienLuongCoBanPagedList(form.Pagenumber);
            return RedirectToAction("TienLuongCoBan", new { status = form.MessageCreateTienLuongCoBan });
        }

        //Edit TienLuongCoBan
        public ActionResult ChinhSuaTienLuongCoBan(TienLuongCoBanForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TienLuongCoBan editCap = this.TienLuongCoBanDelegate.BuildEditTienLuongCoBan(form);
            if (!string.IsNullOrEmpty(form.TienLuongCB))
            {

                try
                {
                    this.TienLuongCoBanDelegate.UpdateTienLuongCoBan(editCap);
                    form.MessageEditTienLuongCoBan = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditTienLuongCoBan = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.TienLuongCoBanPagedList = TienLuongCoBanDelegate.GetTienLuongCoBanPagedList(form.Pagenumber);
            form.RecycleTienLuongCoBanPagedList = TienLuongCoBanDelegate.RecycleGetTienLuongCoBanPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/TienLuongCoBan.aspx", form);
        }
        public JsonResult DeleteTienLuongCoBan(string TienLuongCoBanId)// id la IdTienLuongCoBan
        {
            dm_TienLuongCoBan DeleteCap = this.TienLuongCoBanDelegate.GetTienLuongCoBanById(TienLuongCoBanId.ToString());
            DeleteCap.IsDelete = true;
            if (this.TienLuongCoBanDelegate.DeleteTienLuongCoBan(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục phụ cấp tiền lương cơ bản
        public ActionResult TimKiemTienLuongCoBan(string TienLuongCoBan, int? PageNumber)// id : page number
        {
            TienLuongCoBanForm form = new TienLuongCoBanForm();
            if (TienLuongCoBan == null)
            {
                TienLuongCoBan = "";
            }
            form.id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(TienLuongCoBan);
            if (!string.IsNullOrEmpty(TienLuongCoBan))
            {
                TienLuongCoBan = TienLuongCoBan.Replace(".", "");
                form.TienLuongCoBanPagedList = TienLuongCoBanDelegate.SearchTienLuongCoBanPagedList(PageNumber, TienLuongCoBan);// id : page number
            }
            else
            {
                form.TienLuongCoBanPagedList = TienLuongCoBanDelegate.GetTienLuongCoBanPagedList(PageNumber);
            }
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TienLuongCoBan.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTienLuongCoBanExistAjax(string TienLuongCoBan, int id)
        {
            decimal TienPC;
            if (!string.IsNullOrEmpty(TienLuongCoBan))
                TienPC = decimal.Parse(TienLuongCoBan.Replace(".", ""));
            else return Json(false, JsonRequestBehavior.AllowGet);
            dm_TienLuongCoBan item = this.TienLuongCoBanDelegate.GetTienLuongCoBanByTenCheck(TienPC);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult TienLuongCoBanEditAjax(string id)
        {
            dm_TienLuongCoBan item = this.TienLuongCoBanDelegate.GetTienLuongCoBanById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TienLuongCoBan != null ? item.TienLuongCoBan.Value.ToString("#,#").Replace(",", ".") : "" };
            return Json(kq, JsonRequestBehavior.AllowGet);
            //return Json(item, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiTienLuongCoBan(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.TienLuongCoBanDelegate.PhucHoiTienLuongCoBan(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.TienLuongCoBanDelegate.DeleteTienLuongCoBan(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanTienLuongCoBan(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.TienLuongCoBanDelegate.DeleteTienLuongCoBan(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC tỉnh thành


        TinhThanhDelegate TinhThanhDelegate = new TinhThanhDelegate();

        //....phần xử lý cho DANH MỤC  tỉnh thành .............................................
        public ActionResult TinhThanh(int? PageNumber, string status)// id : page number
        {
            TinhThanhForm TinhThanhForm = new TinhThanhForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                TinhThanhForm.MessageCreateTinhThanh = "Tạo mới thành công !";
            }
            TinhThanhForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            TinhThanhForm.TinhThanhPagedList = TinhThanhDelegate.GetTinhThanhPagedList(PageNumber);
            TinhThanhForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TinhThanh.aspx", TinhThanhForm);
        }
        public ActionResult RecycleBinTinhThanh(int? PageNumber)// id : page number
        {
            TinhThanhForm TinhThanhForm = new TinhThanhForm();
            TinhThanhForm.RecycleTinhThanhPagedList = TinhThanhDelegate.RecycleGetTinhThanhPagedList(PageNumber);
            TinhThanhForm.count = TinhThanhForm.RecycleTinhThanhPagedList.Count;
            TinhThanhForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinTinhThanh.aspx", TinhThanhForm);
        }
        //Create  tỉnh thành
        public ActionResult TaoTinhThanh(TinhThanhForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TinhThanh newTinhThanh = this.TinhThanhDelegate.BuildNewTinhThanh(form);
            if (form.id == -1)
            {
                try
                {
                    newTinhThanh = this.TinhThanhDelegate.AddNewTinhThanh(newTinhThanh);
                    form.MessageCreateTinhThanh = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateTinhThanh = "0";
                }
            }

            //Refesh form
            form.id = newTinhThanh.Id;
            form.TinhThanhPagedList = TinhThanhDelegate.GetTinhThanhPagedList(form.Pagenumber);
            form.RecycleTinhThanhPagedList = TinhThanhDelegate.RecycleGetTinhThanhPagedList(form.Pagenumber);
            return RedirectToAction("TinhThanh", new { status = form.MessageCreateTinhThanh });
        }

        //Edit TinhThanh
        public ActionResult ChinhSuaTinhThanh(TinhThanhForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TinhThanh editCap = this.TinhThanhDelegate.BuildEditTinhThanh(form);
            if (!string.IsNullOrEmpty(form.TenTinh))
            {

                try
                {
                    this.TinhThanhDelegate.UpdateTinhThanh(editCap);
                    form.MessageEditTinhThanh = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditTinhThanh = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.TinhThanhPagedList = TinhThanhDelegate.GetTinhThanhPagedList(form.Pagenumber);
            form.RecycleTinhThanhPagedList = TinhThanhDelegate.RecycleGetTinhThanhPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/TinhThanh.aspx", form);
        }
        public JsonResult DeleteTinhThanh(string TinhThanhId)// id la IdTinhThanh
        {
            dm_TinhThanh DeleteCap = this.TinhThanhDelegate.GetTinhThanhById(TinhThanhId.ToString());
            DeleteCap.IsDelete = true;
            if (this.TinhThanhDelegate.DeleteTinhThanh(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục  tỉnh thành
        public ActionResult TimKiemTinhThanh(string TinhThanh, int? PageNumber)// id : page number
        {
            TinhThanhForm form = new TinhThanhForm();
            if (TinhThanh == null)
            {
                TinhThanh = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(TinhThanh);
            if (!string.IsNullOrEmpty(TinhThanh))
            {
                TinhThanh = TinhThanh.Replace(".", "");
            }
            form.TinhThanhPagedList = TinhThanhDelegate.SearchTinhThanhPagedList(PageNumber, TinhThanh);// id : page number
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TinhThanh.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTinhThanhExistAjax(string TenTinh, int id)
        {
            decimal TienPC;
            dm_TinhThanh item = this.TinhThanhDelegate.GetTinhThanhByTenCheck(TenTinh);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult TinhThanhEditAjax(string id)
        {
            dm_TinhThanh item = this.TinhThanhDelegate.GetTinhThanhById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TenTinh};
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiTinhThanh(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.TinhThanhDelegate.PhucHoiTinhThanh(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.TinhThanhDelegate.DeleteTinhThanh(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanTinhThanh(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.TinhThanhDelegate.DeleteTinhThanh(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC tôn giáo


        TonGiaoDelegate TonGiaoDelegate = new TonGiaoDelegate();

        //....phần xử lý cho DANH MỤC tôn giáo .............................................
        public ActionResult TonGiao(int? PageNumber, string status)// id : page number
        {
            TonGiaoForm TonGiaoForm = new TonGiaoForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                TonGiaoForm.MessageCreateTonGiao = "Tạo mới thành công !";
            }
            TonGiaoForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            TonGiaoForm.TonGiaoPagedList = TonGiaoDelegate.GetTonGiaoPagedList(PageNumber);
            TonGiaoForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TonGiao.aspx", TonGiaoForm);
        }
        public ActionResult RecycleBinTonGiao(int? PageNumber)// id : page number
        {
            TonGiaoForm TonGiaoForm = new TonGiaoForm();
            TonGiaoForm.RecycleTonGiaoPagedList = TonGiaoDelegate.RecycleGetTonGiaoPagedList(PageNumber);
            TonGiaoForm.count = TonGiaoForm.RecycleTonGiaoPagedList.Count;
            TonGiaoForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinTonGiao.aspx", TonGiaoForm);
        }
        //Create tôn giáo
        public ActionResult TaoTonGiao(TonGiaoForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TonGiao newTonGiao = this.TonGiaoDelegate.BuildNewTonGiao(form);
            if (form.id == -1)
            {
                try
                {
                    newTonGiao = this.TonGiaoDelegate.AddNewTonGiao(newTonGiao);
                    form.MessageCreateTonGiao = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateTonGiao = "0";
                }
            }

            //Refesh form
            form.id = newTonGiao.Id;
            form.TonGiaoPagedList = TonGiaoDelegate.GetTonGiaoPagedList(form.Pagenumber);
            form.RecycleTonGiaoPagedList = TonGiaoDelegate.RecycleGetTonGiaoPagedList(form.Pagenumber);
            return RedirectToAction("TonGiao", new { status = form.MessageCreateTonGiao });
        }

        //Edit TonGiao
        public ActionResult ChinhSuaTonGiao(TonGiaoForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TonGiao editCap = this.TonGiaoDelegate.BuildEditTonGiao(form);
            if (!string.IsNullOrEmpty(form.TenTonGiao))
            {

                try
                {
                    this.TonGiaoDelegate.UpdateTonGiao(editCap);
                    form.MessageEditTonGiao = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditTonGiao = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.TonGiaoPagedList = TonGiaoDelegate.GetTonGiaoPagedList(form.Pagenumber);
            form.RecycleTonGiaoPagedList = TonGiaoDelegate.RecycleGetTonGiaoPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/TonGiao.aspx", form);
        }
        public JsonResult DeleteTonGiao(string TonGiaoId)// id la IdTonGiao
        {
            dm_TonGiao DeleteCap = this.TonGiaoDelegate.GetTonGiaoById(TonGiaoId.ToString());
            DeleteCap.IsDelete = true;
            if (this.TonGiaoDelegate.DeleteTonGiao(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục tôn giáo
        public ActionResult TimKiemTonGiao(string TonGiao, int? PageNumber)// id : page number
        {
            TonGiaoForm form = new TonGiaoForm();
            if (TonGiao == null)
            {
                TonGiao = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(TonGiao);
            if (!string.IsNullOrEmpty(TonGiao))
            {
                TonGiao = TonGiao.Replace(".", "");
            }
            form.TonGiaoPagedList = TonGiaoDelegate.SearchTonGiaoPagedList(PageNumber, TonGiao);// id : page number
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TonGiao.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTenTonGiaoExistAjax(string TenTonGiao, int id)
        {
            decimal TienPC;
            dm_TonGiao item = this.TonGiaoDelegate.GetTonGiaoByTenCheck(TenTonGiao);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult TonGiaoEditAjax(string id)
        {
            dm_TonGiao item = this.TonGiaoDelegate.GetTonGiaoById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TenTonGiao };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiTonGiao(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.TonGiaoDelegate.PhucHoiTonGiao(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.TonGiaoDelegate.DeleteTonGiao(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanTonGiao(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.TonGiaoDelegate.DeleteTonGiao(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC tiền trách nhiệm


        TrachNhiemDelegate TrachNhiemDelegate = new TrachNhiemDelegate();

        //....phần xử lý cho DANH MỤC phụ cấp trách nhiệm .............................................
        public ActionResult TrachNhiem(int? PageNumber, string status)// id : page number
        {
            TrachNhiemForm TrachNhiemForm = new TrachNhiemForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                TrachNhiemForm.MessageCreateTrachNhiem = "Tạo mới thành công !";
            }
            TrachNhiemForm.id = -1; //Mặc định _ dấu hiệu tạo mới;
            TrachNhiemForm.TrachNhiemPagedList = TrachNhiemDelegate.GetTrachNhiemPagedList(PageNumber);
            TrachNhiemForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TrachNhiem.aspx", TrachNhiemForm);
        }
        public ActionResult RecycleBinTrachNhiem(int? PageNumber)// id : page number
        {
            TrachNhiemForm TrachNhiemForm = new TrachNhiemForm();
            TrachNhiemForm.RecycleTrachNhiemPagedList = TrachNhiemDelegate.RecycleGetTrachNhiemPagedList(PageNumber);
            TrachNhiemForm.count = TrachNhiemForm.RecycleTrachNhiemPagedList.Count;
            TrachNhiemForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/RecycleBinTrachNhiem.aspx", TrachNhiemForm);
        }
        //Create phục cấp trách nhiệm
        public ActionResult TaoTrachNhiem(TrachNhiemForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TrachNhiem newTrachNhiem = this.TrachNhiemDelegate.BuildNewTrachNhiem(form);
            if (form.id == -1)
            {
                try
                {
                    newTrachNhiem = this.TrachNhiemDelegate.AddNewTrachNhiem(newTrachNhiem);
                    form.MessageCreateTrachNhiem = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateTrachNhiem = "0";
                }
            }

            //Refesh form
            form.id = newTrachNhiem.Id;
            form.TrachNhiemPagedList = TrachNhiemDelegate.GetTrachNhiemPagedList(form.Pagenumber);
            form.RecycleTrachNhiemPagedList = TrachNhiemDelegate.RecycleGetTrachNhiemPagedList(form.Pagenumber);
            return RedirectToAction("TrachNhiem", new { status = form.MessageCreateTrachNhiem });
        }

        //Edit TrachNhiem
        public ActionResult ChinhSuaTrachNhiem(TrachNhiemForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TrachNhiem editCap = this.TrachNhiemDelegate.BuildEditTrachNhiem(form);
            if (!string.IsNullOrEmpty(form.TienTrachNhiem))
            {

                try
                {
                    this.TrachNhiemDelegate.UpdateTrachNhiem(editCap);
                    form.MessageEditTrachNhiem = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditTrachNhiem = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.TrachNhiemPagedList = TrachNhiemDelegate.GetTrachNhiemPagedList(form.Pagenumber);
            form.RecycleTrachNhiemPagedList = TrachNhiemDelegate.RecycleGetTrachNhiemPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/TrachNhiem.aspx", form);
        }
        public JsonResult DeleteTrachNhiem(string TrachNhiemId)// id la IdTrachNhiem
        {
            dm_TrachNhiem DeleteCap = this.TrachNhiemDelegate.GetTrachNhiemById(TrachNhiemId.ToString());
            DeleteCap.IsDelete = true;
            if (this.TrachNhiemDelegate.DeleteTrachNhiem(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục phụ cấp trách nhiệm
        public ActionResult TimKiemTrachNhiem(string TrachNhiem, int? PageNumber)// id : page number
        {
            TrachNhiemForm form = new TrachNhiemForm();
            if (TrachNhiem == null)
            {
                TrachNhiem = "";
            }


            form.id = -1; //Mặc định _ dấu hiệu tạo mới
            form.valuesearch = Convert.ToString(TrachNhiem);
            if (!string.IsNullOrEmpty(TrachNhiem))
            {
                TrachNhiem = TrachNhiem.Replace(".", "");
                form.TrachNhiemPagedList = TrachNhiemDelegate.SearchTrachNhiemPagedList(PageNumber, TrachNhiem);// id : page number
            }
            else
            {
                form.TrachNhiemPagedList = TrachNhiemDelegate.GetTrachNhiemPagedList(PageNumber);
            }
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TrachNhiem.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckTienTrachNhiemExistAjax(string TienTrachNhiem, int id)
        {
            decimal TienPC;
            if (!string.IsNullOrEmpty(TienTrachNhiem))
                TienPC = decimal.Parse(TienTrachNhiem.Replace(".", ""));
            else return Json(false, JsonRequestBehavior.AllowGet);
            dm_TrachNhiem item = this.TrachNhiemDelegate.GetTrachNhiemByTenCheck(TienPC);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult TrachNhiemEditAjax(string id)
        {
            dm_TrachNhiem item = this.TrachNhiemDelegate.GetTrachNhiemById(id);

            string[] kq = new string[] { item.Id.ToString(), item.TienTrachNhiem != null ? item.TienTrachNhiem.Value.ToString("#,#").Replace(",", ".") : "" };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        public JsonResult PhucHoiTrachNhiem(string IdPhucHoi)
        {
            int t = 0;
            string[] arrID = IdPhucHoi.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                int kqdelete = this.TrachNhiemDelegate.PhucHoiTrachNhiem(Convert.ToInt32(arrID[i]));
                if (kqdelete == 1)
                {
                    this.TrachNhiemDelegate.DeleteTrachNhiem(Convert.ToInt32(arrID[i]));
                    t = 1;
                }
                else if (kqdelete == 2)
                    t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        public JsonResult CleanTrachNhiem(string Id)
        {
            int t = 0;
            string[] arrID = Id.Split(',');
            for (int i = 0; i < arrID.Length - 1; i++)
            {
                this.TrachNhiemDelegate.DeleteTrachNhiem(Convert.ToInt32(arrID[i]));
                t = 1;
            }

            return t != 0 ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC Buổi


        BuoiDelegate BuoiDelegate = new BuoiDelegate();

        //....phần xử lý cho DANH MỤC  buổi .............................................
        public ActionResult Buoi(int? PageNumber, string status)// id : page number
        {
            BuoiForm BuoiForm = new BuoiForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                BuoiForm.MessageCreateBuoi = "Tạo mới thành công !";
            }
            BuoiForm.Id = -1; //Mặc định _ dấu hiệu tạo mới;
            IEnumerable<dm_SoKm> list = SoKmDelegate.GetAllSoKm();
            BuoiForm.cboSoKm = new SelectList(list,"Id","Name");
            BuoiForm.BuoiPagedList = BuoiDelegate.GetBuoiPagedList(PageNumber);
            BuoiForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/Buoi.aspx", BuoiForm);
        }
        
        //Create  buổi
        public ActionResult TaoBuoi(BuoiForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_Buoi newBuoi = this.BuoiDelegate.BuildNewBuoi(form);
            if (form.Id == -1)
            {
                try
                {
                    newBuoi = this.BuoiDelegate.AddNewBuoi(newBuoi);
                    form.MessageCreateBuoi = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateBuoi = "0";
                }
            }

            //Refesh form
            form.Id = newBuoi.Id;
            form.BuoiPagedList = BuoiDelegate.GetBuoiPagedList(form.Pagenumber);
            return RedirectToAction("Buoi", new { status = form.MessageCreateBuoi });
        }

        //Edit Buoi
        public ActionResult ChinhSuaBuoi(BuoiForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_Buoi editCap = this.BuoiDelegate.BuildEditBuoi(form);
            if (!string.IsNullOrEmpty(form.Name))
            {

                try
                {
                    this.BuoiDelegate.UpdateBuoi(editCap);
                    form.MessageEditBuoi = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditBuoi = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.cboSoKm = new SelectList(SoKmDelegate.GetAllSoKm(), "Id", "Name");
            form.BuoiPagedList = BuoiDelegate.GetBuoiPagedList(PageNumber);

            return View("~/Views/QuanLyDanhMuc/Buoi.aspx", form);
        }
        public JsonResult DeleteBuoi(string BuoiId)// id la IdBuoi
        {
            dm_Buoi DeleteCap = this.BuoiDelegate.GetBuoiById(BuoiId.ToString());
            DeleteCap.IsDelete = true;
            if (this.BuoiDelegate.DeleteBuoi(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục  buổi
        public ActionResult TimKiemBuoi(string Buoi, int? PageNumber)// id : page number
        {
            BuoiForm form = new BuoiForm();
            if (Buoi == null)
            {
                Buoi = "";
            }


            form.Id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(Buoi);
            if (!string.IsNullOrEmpty(Buoi))
            {
                Buoi = Buoi.Replace(".", "");
            }
            form.BuoiPagedList = BuoiDelegate.SearchBuoiPagedList(PageNumber, Buoi);// id : page number
            form.Pagenumber = PageNumber ?? 1;
            form.cboSoKm = new SelectList(SoKmDelegate.GetAllSoKm(), "Id", "Name");

            return View("~/Views/QuanLyDanhMuc/Buoi.aspx", form);
        }

        
        public JsonResult BuoiEditAjax(string id)
        {
            dm_Buoi item = this.BuoiDelegate.GetBuoiById(id);

            string[] kq = new string[] { item.Id.ToString(),item.Name};
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region phần xử lý cho DANH MỤC số km


        SoKmDelegate SoKmDelegate = new SoKmDelegate();

        //....phần xử lý cho DANH MỤC  số km .............................................
        public ActionResult SoKm(int? PageNumber, string status)// id : page number
        {
            SoKmForm SoKmForm = new SoKmForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                SoKmForm.MessageCreateSoKm = "Tạo mới thành công !";
            }
            SoKmForm.Id = -1; //Mặc định _ dấu hiệu tạo mới;
            SoKmForm.SoKmPagedList = SoKmDelegate.GetSoKmPagedList(PageNumber);
            SoKmForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/SoKm.aspx", SoKmForm);
        }
        
        //Create  số km
        public ActionResult TaoSoKm(SoKmForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_SoKm newSoKm = this.SoKmDelegate.BuildNewSoKm(form);
            if (form.Id == -1)
            {
                try
                {
                    newSoKm = this.SoKmDelegate.AddNewSoKm(newSoKm);
                    form.MessageCreateSoKm = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateSoKm = "0";
                }
            }

            //Refesh form
            form.Id = newSoKm.Id;
            form.SoKmPagedList = SoKmDelegate.GetSoKmPagedList(form.Pagenumber);
            return RedirectToAction("SoKm", new { status = form.MessageCreateSoKm });
        }

        //Edit SoKm
        public ActionResult ChinhSuaSoKm(SoKmForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_SoKm editCap = this.SoKmDelegate.BuildEditSoKm(form);
            if (!string.IsNullOrEmpty(form.Name))
            {

                try
                {
                    this.SoKmDelegate.UpdateSoKm(editCap);
                    form.MessageEditSoKm = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditSoKm = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.SoKmPagedList = SoKmDelegate.GetSoKmPagedList(form.Pagenumber);
            return View("~/Views/QuanLyDanhMuc/SoKm.aspx", form);
        }
        public JsonResult DeleteSoKm(string SoKmId)// id la IdSoKm
        {
            dm_SoKm DeleteCap = this.SoKmDelegate.GetSoKmById(SoKmId.ToString());
            DeleteCap.IsDelete = true;
            if (this.SoKmDelegate.DeleteSoKm(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục  số km
        public ActionResult TimKiemSoKm(string SoKm, int? PageNumber)// id : page number
        {
            SoKmForm form = new SoKmForm();
            if (SoKm == null)
            {
                SoKm = "";
            }


            form.Id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(SoKm);
            if (!string.IsNullOrEmpty(SoKm))
            {
                SoKm = SoKm.Replace(".", "");
            }
            form.SoKmPagedList = SoKmDelegate.SearchSoKmPagedList(PageNumber, SoKm);// id : page number
            form.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/SoKm.aspx", form);
        }

        //para ten : Tên nơi lưu trữ
        public JsonResult DoCheckSoKmExistAjax(string TenTinh, int id)
        {
            decimal TienPC;
            dm_SoKm item = this.SoKmDelegate.GetSoKmByTenCheck(TenTinh);
            bool result;
            if (id == -1)
                result = item != null ? true : false;
            else
            {
                if (item != null)
                {
                    result = item.Id != id ? true : false;
                }
                else
                    result = false;

            }
            return this.Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult SoKmEditAjax(string id)
        {
            dm_SoKm item = this.SoKmDelegate.GetSoKmById(id);

            string[] kq = new string[] { item.Id.ToString(), item.Name, item.MoTa };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region phần xử lý cho DANH MỤC tiền buồi dưỡng


        TienBoiDuongDelegate TienBoiDuongDelegate = new TienBoiDuongDelegate();

        //....phần xử lý cho DANH MỤC  tiền buồi dưỡng .............................................
        public ActionResult TienBoiDuong(int? PageNumber, string status)// id : page number
        {
            TienBoiDuongForm TienBoiDuongForm = new TienBoiDuongForm();
            if (status == "1" && (PageNumber == 1 || PageNumber == null))
            {
                TienBoiDuongForm.MessageCreateTienBoiDuong = "Tạo mới thành công !";
            }
            TienBoiDuongForm.Id = -1; //Mặc định _ dấu hiệu tạo mới;
            TienBoiDuongForm.TienBoiDuongPagedList = TienBoiDuongDelegate.GetTienBoiDuongPagedList(PageNumber);
            TienBoiDuongForm.cboSoKm = new SelectList(SoKmDelegate.GetAllSoKm(), "Id","Name");
            TienBoiDuongForm.cboBuoi = new SelectList(BuoiDelegate.GetAllBuoi(), "Id","Name");
            TienBoiDuongForm.Pagenumber = PageNumber ?? 1;

            return View("~/Views/QuanLyDanhMuc/TienBoiDuong.aspx", TienBoiDuongForm);
        }
        //Create  tiền buồi dưỡng
        public ActionResult TaoTienBoiDuong(TienBoiDuongForm form, int? PageNumber)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TienBoiDuong newTienBoiDuong = this.TienBoiDuongDelegate.BuildNewTienBoiDuong(form);
            if (form.Id == -1)
            {
                try
                {
                    newTienBoiDuong = this.TienBoiDuongDelegate.AddNewTienBoiDuong(newTienBoiDuong);
                    form.MessageCreateTienBoiDuong = "1";
                }
                catch (Exception)
                {
                    form.MessageCreateTienBoiDuong = "0";
                }
            }

            //Refesh form
            form.Id = newTienBoiDuong.Id;
            form.TienBoiDuongPagedList = TienBoiDuongDelegate.GetTienBoiDuongPagedList(form.Pagenumber);
            return RedirectToAction("TienBoiDuong", new { status = form.MessageCreateTienBoiDuong });
        }

        //Edit TienBoiDuong
        public ActionResult ChinhSuaTienBoiDuong(TienBoiDuongForm form, int? PageNumber, int? id)
        {
            //Lấy thông tin Job Title mới từ Form
            dm_TienBoiDuong editCap = this.TienBoiDuongDelegate.BuildEditTienBoiDuong(form);
            if (!string.IsNullOrEmpty(form.SoTien))
            {

                try
                {
                    this.TienBoiDuongDelegate.UpdateTienBoiDuong(editCap);
                    form.MessageEditTienBoiDuong = "Chỉnh sửa thành công !";
                }
                catch (Exception)
                {
                    form.MessageEditTienBoiDuong = "Chỉnh sửa thất bại !";
                }
            }
            //Refesh form
            form.TienBoiDuongPagedList = TienBoiDuongDelegate.GetTienBoiDuongPagedList(form.Pagenumber);
            form.cboSoKm = new SelectList(SoKmDelegate.GetAllSoKm(), "Id", "Name");
            form.cboBuoi = new SelectList(BuoiDelegate.GetAllBuoi(), "Id", "Name");
            return View("~/Views/QuanLyDanhMuc/TienBoiDuong.aspx", form);
        }
        public JsonResult DeleteTienBoiDuong(string TienBoiDuongId)// id la IdTienBoiDuong
        {
            dm_TienBoiDuong DeleteCap = this.TienBoiDuongDelegate.GetTienBoiDuongById(TienBoiDuongId.ToString());
            DeleteCap.IsDelete = true;
            if (this.TienBoiDuongDelegate.DeleteTienBoiDuong(DeleteCap) == 1)
                return Json(true, JsonRequestBehavior.AllowGet);
            else
                return Json(false, JsonRequestBehavior.AllowGet);

        }

        //Search Danh mục  tiền buồi dưỡng
        public ActionResult TimKiemTienBoiDuong(string TienBoiDuong, int? PageNumber)// id : page number
        {
            TienBoiDuongForm form = new TienBoiDuongForm();
            if (TienBoiDuong == null)
            {
                TienBoiDuong = "";
            }


            form.Id = -1; //Mặc định _ dấu hiệu tạo mới;
            form.valuesearch = Convert.ToString(TienBoiDuong);
            if (!string.IsNullOrEmpty(TienBoiDuong))
            {
                TienBoiDuong = TienBoiDuong.Replace(".", "");
            }
            form.TienBoiDuongPagedList = TienBoiDuongDelegate.SearchTienBoiDuongPagedList(PageNumber, TienBoiDuong);// id : page number
            form.Pagenumber = PageNumber ?? 1;
            form.cboSoKm = new SelectList(SoKmDelegate.GetAllSoKm(), "Id", "Name");
            form.cboBuoi = new SelectList(BuoiDelegate.GetAllBuoi(), "Id", "Name");
            return View("~/Views/QuanLyDanhMuc/TienBoiDuong.aspx", form);
        }
        public JsonResult TienBoiDuongEditAjax(string id)
        {
            dm_TienBoiDuong item = this.TienBoiDuongDelegate.GetTienBoiDuongById(id);

            string[] kq = new string[] { item.Id.ToString(),item.IdSoKm!=null?item.IdSoKm.Value.ToString():"0", item.IdBuoi!=null?item.IdBuoi.Value.ToString():"0",item.SoTien!=null?item.SoTien.Value.ToString("#,#").Replace(",","."):"" };
            return Json(kq, JsonRequestBehavior.AllowGet);
        }

        //public JsonResult SelectBuoinAjax(int id)
        //{
        //    IList<dm_Buoi> ListBuoi = BuoiDelegate.GetAllBuoiByIdSoKm(id);
        //    IList<object> obj = new List<object>();
        //    foreach (var item in ListBuoi)
        //    {
        //        obj.Add(new {Value = item.Id,Name =item.Name});
        //    }
        //    return Json(obj, JsonRequestBehavior.AllowGet);
        //}
        public JsonResult BuilThuongKm()
        {
            string str = string.Empty;
            //str += "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"1\" class=\"table_home\">"+
            //    " <tbody><tr><td nowrap=\"nowrap\" align=\"center\"> <strong>STT</strong>"+
            //    "</td><td nowrap=\"nowrap\" align=\"center\"> <strong>Họ</strong> </td>"+
            //    " <td nowrap=\"nowrap\" align=\"center\"><strong>Tên</strong></td>"+
            //    "<td nowrap=\"nowrap\" align=\"center\"><strong>Thứ hai - 08/04/2013 </strong></td></tr>"+
            //    "<tr><td nowrap=\"nowrap\" align=\"center\">1</td>"+
            //    "<td nowrap=\"nowrap\" style=\"padding-left: 5px; text-align:left;\">Nguyễn Phương</td></tr></table>";
            IList<dm_SoKm> listSoKm = SoKmDelegate.GetAllSoKm();
            IList<dm_Buoi> listBuoi = BuoiDelegate.GetAllBuoi();
            int TongDongCuaSoKm = listSoKm.Count;
            int TongDongCuaBuoi = listBuoi.Count;
            str += "<table width=\"100%\" border='1' class=\"table_home\">";
            str += "<tr><td nowrap=\"nowrap\" align=\"center\" style=\"background:#6E6F70;color:#FFFFFF\"> <strong>&nbsp;</strong></td>";
            for (int i = 0; i < TongDongCuaBuoi; i++)
            {
                str += "<td nowrap=\"nowrap\" align=\"center\" style=\"background:#6E6F70;color:#FFFFFF\"> <strong>"+listBuoi[i].Name+"</strong></td>";
            }
            str += "</tr>";
            for (int j = 0; j < TongDongCuaSoKm; j++)
            {
                if(j%2==0)
                    str += "<tr style=\"background:#F1F0ED;\"><td nowrap=\"nowrap\" style=\"padding-left: 5px;text-align:left;\"> <strong>" + listSoKm[j].Name + "</strong></td>";
                else
                    str += "<tr><td nowrap=\"nowrap\" style=\"padding-left: 5px;text-align:left\"> <strong>" + listSoKm[j].Name + "</strong></td>";
                for (int K = 0; K < TongDongCuaBuoi; K++)
                {
                    str += "<td nowrap=\"nowrap\" style=\"text-align:center\"><strong>";
                    decimal sotien = TienBoiDuongDelegate.GetSoTienBoiDuong(listBuoi[K].Id, listSoKm[j].Id);
                    if (sotien != 0)
                    {
                        str += sotien.ToString("#,#0").Replace(",", ".") + "<input type=\"text\" id=\""+listBuoi[K].Name+"/"+listSoKm[j].Name+"\" style=\"width:30px\"></strong></td>";
                    }
                    else 
                        str += sotien.ToString("#,#0").Replace(",", ".") + "</strong></td>";
                }
                str += "</tr>";
            }
            str += "</table>";
            return Json(str, JsonRequestBehavior.AllowGet);

        }
        #endregion
    }
}
